/**
 * 
 */
package org.jenkon.assertion;

import java.io.File;

/**
 * class with assertion methods for file handling.
 * 
 * @author jkonopka
 * 
 */
public final class FileAssert {

	/**
	 * hide public constructor for this util class.
	 */
	private FileAssert() {
	}

	/**
	 * If the file does not exist, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File} to check of exist.
	 * @throws IllegalArgumentException if the file does not exist
	 */
	public static void exists(final File file) {
		exists(file, String.format("the file '%s' doesn't exists.", file));
	}

	/**
	 * If the file does not exist, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File} to check
	 * @param message the throwing message
	 * @throws IllegalArgumentException if the file does not exist
	 */
	public static void exists(final File file, final String message) {
		Assert.isTrue(file.exists(), message);
	}

	/**
	 * If the file can not read, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @throws IllegalArgumentException
	 */
	public static void canRead(final File file) {
		canRead(file, String.format("cannot read the file '%s'.", file));
	}

	/**
	 * If the file can not read, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @param message the throwing message
	 * @throws IllegalArgumentException
	 */
	public static void canRead(final File file, final String message) {
		Assert.isTrue(file.canRead(), message);
	}

	/**
	 * @param file the {@link File}
	 */
	public static void canWrite(final File file) {
		canWrite(file, String.format("cannot write the file '%s'.", file));
	}

	/**
	 * @param file the {@link File}
	 * @param message the throwing message
	 */
	public static void canWrite(final File file, final String message) {
		Assert.isTrue(file.canWrite(), message);
	}

	/**
	 * @param file the {@link File}
	 */
	public static void canExecute(final File file) {
		canExecute(file, String.format("cannot execute the file '%s'.", file));
	}

	/**
	 * @param file the {@link File}
	 * @param message the throwing message
	 */
	public static void canExecute(final File file, final String message) {
		Assert.isTrue(file.canExecute(), message);
	}

	/**
	 * @param file the {@link File}
	 */
	public static void isDirectory(final File file) {
		isDirectory(file, String.format("'%s' is not a directory.", file));
	}

	/**
	 * @param file the {@link File}
	 * @param message the throwing message
	 */
	public static void isDirectory(final File file, final String message) {
		Assert.isTrue(file.isDirectory(), message);
	}

	/**
	 * If the file is not a file, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @throws IllegalArgumentException if the file is not a file
	 */
	public static void isFile(final File file) {
		isFile(file, String.format("'%s' is not a file.", file));
	}

	/**
	 * If the file is not a file, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @param message the throwing message
	 * @throws IllegalArgumentException if the file is not a file
	 */
	public static void isFile(final File file, final String message) {
		Assert.isTrue(file.isFile(), message);
	}

	/**
	 * If the file is not hidden, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @throws IllegalArgumentException If the file is not hidden
	 */
	public static void isHidden(final File file) {
		isHidden(file, String.format("'%s' is not hidden.", file));
	}

	/**
	 * If the file is not hidden, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file the {@link File}
	 * @param message the throwing message
	 * @throws IllegalArgumentException If the file is not hidden
	 */
	public static void isHidden(final File file, final String message) {
		Assert.isTrue(file.isHidden(), message);
	}

	/**
	 * If the file is not absolute, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file {@link File}
	 * @throws IllegalArgumentException If the file is not absolute
	 */
	public static void isAbsolute(final File file) {
		isAbsolute(file, "'%s' is not absolute.");
	}

	/**
	 * If the file is not absolute, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param file {@link File}
	 * @param message the throwing message
	 * @throws IllegalArgumentException If the file is not absolute
	 */
	public static void isAbsolute(final File file, final String message) {
		Assert.isTrue(file.isAbsolute(), message);
	}

}
